(function() {
  var i, text, code, codes = document.getElementsByTagName('code');
  for (i = 0; i < codes.length;) {
    code = codes[i];
    text = code.textContent;
    if (/\\/.test(text)) {
      text = text.replace(/\\/g, '\\\\');
      code.textContent = text;
    }
    if (/\$/.test(text)) {
      text = text.replace(/\$/g, '\\$');
      code.textContent = text;
    }
    /*if (/\\\\\s/.test(text)) {
      text = text.replace(/\\\\(\s)/g, '\\\\\\\\$1');
      code.textContent = text;
    }
    if (/\\$$/.test(text)) {
      text = text.replace(/\\$$/g, '\\\\\$');
      code.textContent = text;
    }
    if (/^\$\$[^$]/.test(text) && /[^$]\$\$(.*)$/.test(text)) {
      text = text.replace(/^\$\$/, '\\$\\$').replace(/\$\$(.*)$/, '\\$\\$$$1');
      code.textContent = text;
    }
    if (/^\$[^$]/.test(text) && /[^$]\$(.*)$/.test(text)) {
      text = text.replace(/^(.*)\$(.*[^\$])/, '$1\\$$$2').replace(/([^\$].*)\$(.*)$/, '$1\\$$$2');
      code.textContent = text;
    }*/
    //if (/.*?\$.*?\$/.test(text)) {
    //  text = text.replace(/(.*?\$.+?)\$/, '$1\\\$');
    //  code.textContent = text;
    //}
    i++;
  }
})();
